<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BScreenCreateServiceSummary
 *
 * @author ID59C
 */
class BScreenCreateServiceSummary extends BUIScreen {

    //put your code here
    public $title = "Create Service Summary";
    public $screenActions = array();
    public $btnConfirm;
    public $btnCancel;

    public function render($data = null) {
        
        //add new serviceAppTopBar for createService operation
        Blyn::app()->getActiveServiceApp()->getUIManager()->setRenderView(BUIServiceApp::View_ServiceAppTopBar, 'PersonalService_AppTopBar');

        //$btnConfirm = new BUIButton('confirm');
        $this->btnConfirm = $this->createLink('btnConfirm', array('linkType' => BUIScreen::LinkType_AjaxButton,'label'=>'Confirm'));
        //$btnCancel = new BUIButton('cancel');
        $this->btnCancel = $this->createLink('btnCancel', array('linkType' => BUIScreen::LinkType_AjaxButton,'label'=>'Cancel'));

        //     if ($btnConfirm->isClicked()) {
        if ($this->isAjaxLinkClicked('btnConfirm')) {
            $service = $this->getUINode()->getTransitVariable(BScreenCreateServiceMeta::TRANSIT_VARIABLE_NEWSERVICE);

            $service->setVisible(TRUE);

            //reset user's services list because new service added
            Blyn::app()->getCurrentUser()->resetTransitVariable(BUser::TransitVariable_UserServicesOfRoleType);
            
            //Blyn::app()->getUIManager()->refreshLeftMenu();

            $this->gotoUINode($service->getId(),NULL,NULL,array('refreshLeftMenu'=>TRUE));

            //yii::app()->end();
        }

        //add screenActions with subtitle
        $uiNode = $this->getUINode();
        $this->screenActions = $uiNode->getScreenActionGroup('CreateServiceActions');

        $this->addRenderView('summaryView', 'createServiceSummaryView', array('screen' => $this));

        /*

          $this->addRenderView('pageTitle', 'pageTitle', array('pageTitle' => $this->title));

          foreach ($this->screenActions as $screenAction) {
          $subTitle = $screenAction->getScreen() . '\'s actions:' . $screenAction->getStatus();

          $this->addRenderView('subTitle', 'subtitle', array('subTitle' => $subTitle));

          $detail = $this->getDetailViewData($screenAction);

          $this->addRenderView('detailView', 'detailview', array('detailViewData' => $detail['data'],
          'detailViewAttributes' => $detail['attributes']));
          }

          //add buttons into inline layout view
          if ($this->isMemberOfScreenFlow()) {
          $screenFlow = $this->getParent();
          $url = $screenFlow->getUrl();
          } else {
          $url = $this->getUrl();
          }

          $vBtnConfirm = array('view' => $btnConfirm->getView(), 'data' => $btnConfirm->getData(array('button' => array('label' => 'Confirm', 'url' => $url))));
          $vBtnCancel = array('view' => $btnCancel->getView(), 'data' => $btnCancel->getData(array('button' => array('label' => 'Cancel', 'url' => $url))));
          $views = array();
          array_push($views, $vBtnConfirm);
          array_push($views, $vBtnCancel);
          $this->addRenderView('inline-views', 'inline-views', array('views' => $views, 'uiObj' => $this));
         * 
         */

        //$this->startRender();
    }

    public function getDetailViewData($screenAction) {
        $result = array();
        $detailAttributes = array();
        $datailData = array();
        $inputElements = $screenAction->getInputElements();

        foreach ($inputElements as $element) {
            $name = $element['name'];
            $value = $element['displayValue'] == null ? $element['value'] : $element['displayValue'];
            array_push($detailAttributes, array('name' => $element['name'], 'label' => $element['name']));
            $datailData[$name] = $value;
        }
        $result['data'] = $datailData;
        $result['attributes'] = $detailAttributes;
        return $result;
    }

}

?>
